<template>
  <div class="station-detail p-10 white-space-normal" @mouseleave="$emit('leave')">
    <p class="station-name">{{ info.regionName }}</p>
    <p>
      <span class="title">{{ $t('BELONGS_REGION_NAME') }}：</span>
      <span class="detail">{{ regionList.map(i => i.regionName).join('/') }}</span>
    </p>
    <p class="no-warp">
      <span class="title">{{ $t('GEOGRAPHIC_LOCATION') }}：</span>
      <span class="detail">
        {{ $t('LONGITUDE') }}:{{ info.longitude }}；{{ $t('LATITUDE') }}:{{ info.latitude }}
      </span>
    </p>
    <p v-if="alarmList.length > 0" class="station-name">{{ $t('ALARM_INFORMATION') }}</p>
    <p v-if="alarmList.length > 1">
      <span class="title">{{ $t('NUMBER_OF_ALARMS') }}：</span>
      <span class="detail">{{ alarmList.length }}</span>
    </p>
    <div v-for="(item, index) in alarmList" :key="index" class="mt-5">
      <template v-if="alarmList.length === 1">
        <p>
          <span class="title">{{ $t('ALARM_LEVEL') }}：</span>
          <span class="detail">{{ dictMap['ALARM_LEVEL'][item.alarmLevel] }}</span>
        </p>
        <p>
          <span class="title">{{ $t('ALARM_DEVICE') }}：</span>
          <span class="detail">{{ item.device ? item.device.deviceName : item.deviceId }}</span>
        </p>
        <p>
          <span class="title">{{ $t('ALARM_TYPE') }}：</span>
          <span class="detail">{{ dictMap['ALARM_TYPE'][item.alarmType] }}</span>
        </p>
        <p>
          <span class="title">{{ $t('ALARM_TIME') }}：</span>
          <span class="detail">{{ item.startTime || '' }}</span>
        </p>
        <p>
          <span class="title">{{ $t('CONFIRMATION_STATE') }}：</span>
          <span class="detail">{{
            item.alarmStatus === 'READY' ? $t('ALARM_STATUS_READY') : $t('ALARM_STATUS_CONFIRM')
          }}</span>
        </p>
      </template>
      <template v-else>
        <p>
          <span class="title">（{{ index + 1 }}）</span>
          <span class="detail">
            <span class="mr-5">{{ item.device ? item.device.deviceName : item.deviceId }}</span>
            <span class="mr-5">{{ dictMap['ALARM_TYPE'][item.alarmType] }}</span>
          </span>
        </p>
      </template>
    </div>
  </div>
</template>
<script>
  import { mapGetters } from 'vuex'
  import { getParentsById } from '@/utils/common'
  export default {
    props: {
      stationId: {
        type: String,
        default: ''
      }
    },
    data() {
      return {
        info: {
          regionName: '',
          person: '',
          tel: '',
          address: ''
        },
        regionList: []
      }
    },
    computed: {
      ...mapGetters(['stationTree', 'marqueeList', 'dictMap']),
      alarmList() {
        return this.stationId ? this.marqueeList.filter(i => i.regionId === this.stationId) : []
      }
    },
    watch: {
      stationId: {
        handler(newVal, oldVal) {
          newVal && this.getInfo(newVal)
        }
      }
    },
    methods: {
      getInfo() {
        // console.log('this.stationId', this.stationId)
        if (!this.stationId) return
        const list = getParentsById(this.stationTree, this.stationId, 'regionId') || []
        list.reverse()
        if (list.length) {
          this.info = list.pop()
        }
        this.regionList = list
      }
    }
  }
</script>
<style lang="scss">
  @import '@/assets/css/mixin.module.scss';
  .station-detail {
    max-width: 310px;
    max-height: 300px;
    font-size: 12px;
    line-height: 18 px;
    border-radius: 5px;
    z-index: 5;
    overflow: auto;
    // pointer-events: none;
    @include themeify {
      color: themed('gisValueColor');
      background: themed('homeTooltipBg');
      border: 1px solid themed('homeTooltipBorderColor');
      box-shadow: 0px 0px 10px 0px themed('homeTooltipShadow');
    }
    .station-name {
      font-size: 14px;
    }
    .title {
      @include themeify {
        color: themed('gisTitleColor');
      }
    }
    .detail {
      @include themeify {
        color: themed('gisValueColor');
      }
    }
    p + p {
      margin-top: 5px;
    }
  }
</style>
